 var app = getApp()
 // 处理data
 function getoptions(date) {
   for (var i = 0; i < date.length; i++) {
     date[i].options = date[i].options.split(",")
   }
   return date
 }

 function http(url, method, data) {
   return new Promise((resolve,reject)=>{
    wx.request({
      url: url,
      method: method || 'GET',
      data: data || {},
      header:{
        token:wx.getStorageSync('token'),
      },
      success: res => {
        resolve(res)
      },
      fail:err=>{
        reject(err)
      }
    })
   })
 }

 function getDate() {
   const date = new Date(Date.parse(new Date()) + 60 * 60 * 1000 * 8).toLocaleDateString()
   const dateint = parseInt(date.split('/')[0] + date.split('/')[1] + date.split('/')[2])
   return dateint
 }

 function setWatcher(data, watch) {
   Object.keys(watch).forEach(key => {
     this.observe(data, key, watch[key])
   })
 }

 function observe(obj, key, watchFun) {
   let val = obj[key]
   Object.defineProperty(obj, key, {
     configurable: true,
     enumerable: true,
     set: function (value) {
       watchFun(value, val)
       this.result = true;
       val = value
     },
     get: function () {
       return val
     }
   })
 }

 module.exports = {
   getoptions: getoptions,
   getDate: getDate,
   setWatcher: setWatcher,
   observe: observe,
   http: http,
 }